package fr.cnam.projetSiw.client.structure.pages.suggest;

import java.util.ArrayList;

import com.google.gwt.event.logical.shared.SelectionEvent;
import com.google.gwt.event.logical.shared.SelectionHandler;
import com.google.gwt.event.logical.shared.ValueChangeEvent;
import com.google.gwt.event.logical.shared.ValueChangeHandler;
import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HasVerticalAlignment;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.MultiWordSuggestOracle;
import com.google.gwt.user.client.ui.SuggestBox;
import com.google.gwt.user.client.ui.SuggestOracle;
import com.google.gwt.user.client.ui.SuggestOracle.Suggestion;

public class SuggestGenreViewImpl extends Composite implements SuggestGenreView{

	private HorizontalPanel hp = new HorizontalPanel();
	private SuggestBox suggest;
	private Command suggestChangeCommand;
	private Presenter presenter;


	public SuggestGenreViewImpl(){
		initWidget(hp);
		hp.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
	}

	@Override
	public void setPresenter(ZicPresenter presenter)
	{
		this.presenter = (Presenter) presenter;

	}
	@Override
	public void setGenreChangedCommand(Command command) {
		suggestChangeCommand = command;
	}
	@Override
	public String getGenre() {
		return suggest.getText();
	}
	@Override
	public void setAllGenre(ArrayList<String> result) {
	    MultiWordSuggestOracle oracle = new MultiWordSuggestOracle();
	    oracle.addAll(result);
	    suggest = new SuggestBox(oracle);
	    suggest.setText("Pop_music");
	    suggest.addSelectionHandler(new SelectionHandler<SuggestOracle.Suggestion>() {
			
			@Override
			public void onSelection(SelectionEvent<Suggestion> event) {
				suggestChangeCommand.execute();				
			}
		});
		hp.add(new Label("Choix du genre : "));
		hp.add(suggest);

	}

}
